home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Burning & Media
/
GB-PVR 1.2.13
/
GBPVR10213.msi
/
Cabs.w1.cab
/
Library2.aspx.cs460
< prev
next >
Wrap
Text File
|
2008-02-23
|
31KB
|
644 lines
//===========================================================================
// This file was modified as part of an ASP.NET 2.0 Web project conversion.
// The class name was changed and the class modified to inherit from the abstract base class
// in file 'App_Code\Migrated\Stub_Library_aspx_cs.cs'.
// During runtime, this allows other classes in your web application to bind and access
// the code-behind page using the abstract base class.
// The associated content page 'Library.aspx' was also modified to refer to the new class name.
// For more information on this code pattern, please refer to http://go.microsoft.com/fwlink/?LinkId=46995
//===========================================================================
using System;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
using GBPVR.Public;
using gbweb.classes;
using TagLib.Id3v2;
using TagLib.Asf;
using File=System.IO.File;
namespace gbweb
{
/// <summary>
/// Summary description for Library.
/// </summary>
public partial class Migrated_Library2 : Library
{
protected string Mode;
protected string DisplayPath;
private Settings guideParams;
private const string folderDiv1 = "<div class=\"folder\">";
private const string endDiv = "</div>";
private const string fileDiv1 = "<div class=\"file\">";
private const string tagInfoDiv = "<a class=\"toolTip\" href=\"#\">";
private const string photoDiv1 = "<div id=\"FILE_LIST\">";
private const string streamButton = "<div class=\"butStream\">";
private const string playButton = "<div class=\"butPlay\">";
private const string downloadButton = "<div class=\"butDownload\">";
private const string albumPic1 = "<img src=\"";
private const string albumPic2 = "\" alt=\"\" width=\"240\" height=\"240\" border=\"0\" hspace=\"0\" vspace=\"0\">";
private bool photoLibrary = false;
private string folder = string.Empty;
private Process proc;
private ProcessStartInfo psi;
protected void Page_Load(object sender, EventArgs e)
{
//General housekeeping
Session["GuideStartTime"] = null;
guideParams = Global.Settings;
//Code to prevent Guest users from accessing the Admin and search Pages
if (!Convert.ToBoolean((string)Session["NotGuestUser"]))
{
NAV_SEARCH.Visible = false;
NAV_CONFIG.Visible = false;
}
NAV_TREE.InnerHtml = string.Empty;
//Check to see if the user has VLC installed and configured
bool strmAllowed = File.Exists(Path.Combine(guideParams.strmVLCLoc, "vlc.exe"));
//Intialize a cookie variable
HttpCookie cookie;
//Get the path parameter to see where we are navigating to
string vpath = string.Empty;
string picName = string.Empty;
if (!IsPostBack)
{
//Set the Day/date/time display on the header
viewDate.InnerText = DateTime.Now.ToLongDateString().Trim();
serverTime.InnerText = "Server Time: " + DateTime.Now.ToLongTimeString().Trim();
NAV_RECORDINGS.Visible = guideParams.showManage;
if (Convert.ToBoolean((string)Session["NotGuestUser"]))
{
NAV_SEARCH.Visible = guideParams.showSearch;
}
NAV_VIDEO.Visible = guideParams.showVideoLib;
NAV_MUSIC.Visible = guideParams.showMusicLib;
NAV_PHOTO.Visible = guideParams.showPhotoLib;
NAV_STATS.Visible = guideParams.showStats;
//Get the saved coode for the default size of the photo.....this is remembered from session to session
cookie = Request.Cookies["photoSize"];
photo_Size.SelectedValue = cookie != null ? cookie.Value : "2";
}
if ((Request.Params["pic"] != null) && (Request.Params["pic"].Length !=0))
{
picName = Request.Params["pic"];
}
if ((Request["path"] != null) && (Request["path"].Length != 0))
{
vpath = Request["path"];
if (picName != string.Empty)
{
picture.ImageUrl =
Download.GetDownloadUrl(false, true, Download.InternalFiles.Photo,
PublicDownload.Serialize(Path.Combine(GetRealPath(vpath), picName)));
GRAPHICS.Visible = true;
//Create an image from the file location
Image image =
Image.FromFile(Path.Combine(GetRealPath(vpath), picName));
//Get pull the filename from the picture path to be displayed to the user
string photoinfo = picName;
//Pull the image dimensions from the image to be displayed to the user
photoinfo += " - Actual Size: " + image.Width + "x" + image.Height;
//Set the info lable to the value of the filename of the image and the image dimensions
photoInfo.Text = photoinfo;
//Set the image display size
switch (photo_Size.SelectedValue)
{
case "0":
{
picture.Height = image.Height;
picture.Width = image.Width;
break;
}
case "1":
{
picture.Height = Convert.ToInt32(image.Height*.75);
picture.Width = Convert.ToInt32(image.Width*.75);
break;
}
case "2":
{
picture.Height = Convert.ToInt32(image.Height*.50);
picture.Width = Convert.ToInt32(image.Width*.50);
break;
}
case "3":
{
picture.Height = Convert.ToInt32(image.Height*.25);
picture.Width = Convert.ToInt32(image.Width*.25);
break;
}
case "4":
{
picture.Height = Convert.ToInt32(image.Height*.10);
picture.Width = Convert.ToInt32(image.Width*.10);
break;
}
default:
{
picture.Height = Convert.ToInt32(image.Height*.50);
picture.Width = Convert.ToInt32(image.Width*.50);
break;
}
}
//If the user has choosen to rotate the image then we need to process the image and reset the image sizeing
//to work with the rotation option
if (photo_Rotation.SelectedValue != "0")
{
//We must set the url of the rotated image to call download.ashx so that it can be streamed back to the image control
picture.ImageUrl =
Download.GetDownloadUrl(false, true, Download.InternalFiles.ModifiedPhoto,
PublicDownload.Serialize(Path.Combine(GetRealPath(vpath), picName) + "~" + picture.Height.Value + "~" +
picture.Width.Value + "~" +
photo_Rotation.SelectedValue));
//Depending on the rotation option the height and width of the image control need to be swapped.
switch (photo_Rotation.SelectedValue)
{
case "1":
{
double H = picture.Height.Value;
double W = picture.Width.Value;
picture.Height = Convert.ToInt32(W);
picture.Width = Convert.ToInt32(H);
break;
}
case "3":
{
double H = picture.Height.Value;
double W = picture.Width.Value;
picture.Height = Convert.ToInt32(W);
picture.Width = Convert.ToInt32(H);
break;
}
}
}
//Cleanup
image.Dispose();
}
}
//Store the selected sort order in the cookie for the next image display
cookie = new HttpCookie("photoSize", photo_Size.SelectedValue);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
//Split the path into an array
string[] pathparts = vpath.Split(new char[] {'/'}, 3);
//Set the display to show what library we are looking at....Music or Video
Mode = CultureInfo.CurrentUICulture.TextInfo.ToTitleCase(pathparts[0]);
if (Mode.ToLower() == "music")
{
streamSettings.PostBackUrl = "public/player2.aspx?playerType=2";
streamSettings.Attributes.Add("onclick", "EditPop5(\"public/player2.aspx?playerType=2\",'Add1');return false;");
}
else
{
streamSettings.PostBackUrl = "public/player2.aspx?playerType=1";
streamSettings.Attributes.Add("onclick", "EditPop5(\"public/player2.aspx?playerType=1\",'Add1');return false;");
}
//Set the file extension filter for whatever we are viewing
Regex fileFilter = GetRegex(Mode);
//Set the header tab to active for the appropriate view
switch (Mode.ToLower())
{
case "video":
NAV_VIDEO.Attributes.Add("class", "currentTab");
libraryTitle.InnerText = "Video Library";
NAVIGATION_MUSIC.ID = "NAVIGATION_VIDEO";
libraryBody.Attributes.Clear();
libraryBody.Attributes.Remove("id");
libraryBody.ID = "libraryBody";
libraryBody.Attributes.Add("onload", "GetServerTime(), GetReminders(), StartUp()");
SPACER.Visible = false;
MusicVideoControls.Visible = true;
ALBUM_ART.Visible = false;
playAlbum.Visible = false;
streamAlbum.Visible = false;
streamerSettings.Visible = false;
PHOTO.Visible = false;
PHOTO_INFO.Visible = false;
formPhotoViewer.Visible = false;
photoLibrary = false;
if (GetStreamerStatus() != "")
{
streamMessage.InnerHtml = "Streaming is Active";
}
else
{
streamMessage.InnerHtml = "";
}
break;
case "music":
NAV_MUSIC.Attributes.Add("class", "currentTab");
libraryTitle.InnerText = "Music Library";
NAVIGATION_MUSIC.ID = "NAVIGATION_MUSIC";
libraryBody.Attributes.Clear();
libraryBody.ID = "libraryBody";
libraryBody.Attributes.Add("onload", "GetServerTime(), GetReminders(), StartUp()");
SPACER.Visible = false;
MusicVideoControls.Visible = true;
ALBUM_ART.Visible = false;
playAlbum.Visible = false;
streamAlbum.Visible = false;
streamerSettings.Visible = false;
PHOTO.Visible = false;
PHOTO_INFO.Visible = false;
formPhotoViewer.Visible = false;
photoLibrary = false;
if (GetStreamerStatus() != "")
{
streamMessage.InnerHtml = "Streaming is Active";
}
else
{
streamMessage.InnerHtml = "";
}
break;
case "photo":
NAV_PHOTO.Attributes.Add("class", "currentTab");
libraryTitle.InnerText = "Photo Library";
NAVIGATION_MUSIC.ID = "NAVIGATION_PHOTO";
libraryBody.Attributes.Clear();
libraryBody.ID = "bodyPhoto";
libraryBody.Attributes.Add("onload", "GetServerTime(), GetReminders(),StartUp()");
SPACER.Visible = true;
MusicVideoControls.Visible = false;
ALBUM_ART.Visible = false;
playAlbum.Visible = false;
streamAlbum.Visible = false;
streamerSettings.Visible = false;
PHOTO.Visible = true;
PHOTO_INFO.Visible = true;
formPhotoViewer.Visible = true;
photoLibrary = true;
break;
}
string path = GetRealPath(vpath);
ArrayList folders = new ArrayList();
ArrayList files = new ArrayList();
string albumArtist = string.Empty;
if (pathparts.Length == 1)
{
Hashtable directories = (Hashtable)HttpContext.Current.Session[Mode + "LibraryDirectories"];
ArrayList keys = new ArrayList(directories.Keys);
keys.Sort();
foreach (string name in keys)
folders.Add(name);
}
else
{
if (pathparts.Length == 2)
{
DisplayPath = " - " + pathparts[1];
libraryTitle.InnerText += DisplayPath;
}
else if (pathparts.Length == 3)
{
DisplayPath = " - " + pathparts[1] + "/" + pathparts[2];
libraryTitle.InnerText += DisplayPath;
}
try
{
folders.Add("..");
string[] dirs = Directory.GetDirectories(path);
Array.Sort(dirs);
foreach (string dir in dirs)
{
if (dir == Path.GetFullPath(dir))
folders.Add(Path.GetFileName(dir));
}
string[] filenames = Directory.GetFiles(path);
Array.Sort(filenames);
foreach (string filename in filenames)
{
if (filename == Path.GetFullPath(filename))
{
string fileName = Path.GetFileName(filename);
//Set the header tab to active for the appropriate view
try
{
switch (fileName.Substring(fileName.Length - 3))
{
case "mp3":
TagLib.File file = TagLib.File.Create(filename);
TagLib.Id3v2.Tag id32_tag = file.GetTag(TagLib.TagTypes.Id3v2) as TagLib.Id3v2.Tag;
if (id32_tag != null && !id32_tag.IsEmpty)
{
string tagInfo = string.Empty;
if (id32_tag.Album != null)
{
tagInfo += "<b>Album: </b>" + id32_tag.Album +
"<img height=\"1\" src=\"themes2/common/graphics/spacer.gif\" width=\"7\" border=\"0\"></img>";
}
if (id32_tag.Performers[0] != null)
{
tagInfo += "<b>Artist: </b>" + id32_tag.Performers[0] +
"<img height=\"1\" src=\"themes2/common/graphics/spacer.gif\" width=\"7\" border=\"0\"></img>";
if (albumArtist == string.Empty)
{
albumArtist = id32_tag.Performers[0];
}
}
if (id32_tag.Copyright!= null)
{
tagInfo += "<b>Copyright: </b>" + id32_tag.Copyright +
"<img height=\"1\" src=\"themes2/common/graphics/spacer.gif\" width=\"7\" border=\"0\"></img>";
}
if (id32_tag.Title!= null)
{
tagInfo += "<b>Title: </b>" + id32_tag.Title +
"<img height=\"1\" src=\"themes2/common/graphics/spacer.gif\" width=\"7\" border=\"0\"></img>";
}
if (id32_tag.Track != null)
{
tagInfo += "<b>Track: </b>" + id32_tag.Track +
"<img height=\"1\" src=\"themes2/common/graphics/spacer.gif\" width=\"7\" border=\"0\"></img>"; ;
}
if (id32_tag.Year != null)
{
tagInfo += "<b>Year: </b>" + id32_tag.Year;
}
files.Add(fileName + "|" + tagInfo);
}
else
{
files.Add(fileName + "|");
}
break;
case "wma":
TagLib.File wma_file = TagLib.File.Create(filename);
TagLib.Asf.Tag wma_tag = wma_file.GetTag(TagLib.TagTypes.Asf) as TagLib.Asf.Tag;
if (wma_tag != null && !wma_tag.IsEmpty)
{
string tagInfo = string.Empty;
if (wma_tag.Album != null)
{
tagInfo += "<b>Album: </b>" + wma_tag.Album +
"<img height=\"1\" src=\"themes2/common/graphics/spacer.gif\" width=\"7\" border=\"0\"></img>";
}
if (wma_tag.JoinedAlbumArtists != null)
{
tagInfo += "<b>Artists: </b>" + wma_tag.JoinedAlbumArtists +
"<img height=\"1\" src=\"themes2/common/graphics/spacer.gif\" width=\"7\" border=\"0\"></img>";
if (albumArtist == string.Empty)
{
albumArtist = wma_tag.JoinedAlbumArtists;
}
}
if (wma_tag.Copyright != null)
{
tagInfo += "<b>Copyright: </b>" + wma_tag.Copyright +
"<img height=\"1\" src=\"themes2/common/graphics/spacer.gif\" width=\"7\" border=\"0\"></img>";
}
if (wma_tag.Title != null)
{
tagInfo += "<b>Title: </b>" + wma_tag.Title +
"<img height=\"1\" src=\"themes2/common/graphics/spacer.gif\" width=\"7\" border=\"0\"></img>";
}
if (wma_tag.Track != null)
{
tagInfo += "<b>Track: </b>" + wma_tag.Track +
"<img height=\"1\" src=\"themes2/common/graphics/spacer.gif\" width=\"7\" border=\"0\"></img>"; ;
}
if (wma_tag.Year != null)
{
tagInfo += "<b>Year: </b>" + wma_tag.Year;
}
files.Add(fileName + "|" + tagInfo);
}
else
{
files.Add(fileName + "|");
}
break;
default:
files.Add(fileName + "|");
break;
}
}
catch (Exception ex)
{
files.Add(fileName + "|");
Logger.Error(ex.ToString());
}
}
}
}
catch (Exception ex)
{
Logger.Error(ex.ToString());
}
}
string root = string.Join("/", pathparts);
if (root.Length > 0) root += "/";
ArrayList library = new ArrayList();
foreach (string folder in folders)
{
if (folder != "..")
{
path = Server.UrlEncode(root) + Server.UrlEncode(folder);
}
else
{
path = string.Join("/", pathparts);
path = path.Substring(0, path.LastIndexOf("/"));
path = Server.UrlEncode(path);
}
library.Add(folderDiv1 + "<a href=\"?path=" + path + "\" >[" + folder + "]</a>" + endDiv);
}
Regex coverFilter;
if (albumArtist != string.Empty)
{
coverFilter =
new Regex(Global.Settings.coverFiles.Replace("~", albumArtist), RegexOptions.Compiled | RegexOptions.IgnoreCase);
}
else
{
coverFilter =
new Regex(Global.Settings.coverFiles.Replace("~|", ""), RegexOptions.Compiled | RegexOptions.IgnoreCase);
}
string mediaButton = string.Empty;
if (photoLibrary)
{
library.Add(photoDiv1);
}
foreach (string file in files)
{
//Pull out Tag info if present
string[] fileParts = file.Split(new char[] { '|' }, 2);
if (!photoLibrary)
{
if (fileFilter.IsMatch(fileParts[0]))
{
string fileName = string.Empty;
mediaButton = string.Empty;
playAlbum.Visible = true;
if (fileParts.Length > 1 && fileParts[1].Length > 0)
{
fileName = fileDiv1 + tagInfoDiv + fileParts[0] + "<span>" + fileParts[1] + "</span></a></br>";
}
else
{
fileName = fileDiv1 + fileParts[0] + "</br>";
}
library.Add(fileName);
if (strmAllowed)
{
if (Mode.ToLower() == "music")
{
mediaButton += streamButton + "<a href=\"public/Player2.aspx?playerType=2&path=" + Server.UrlEncode(root.Substring(0, root.Length - 1)) + "&mvid=" + Server.UrlEncode(PublicDownload.Serialize(root + fileParts[0])) + "\" onclick=\"EditPop5(this.href,'Add1');return false;\" >Stream</a></div>";
}
else
{
mediaButton += streamButton + "<a href=\"public/Player2.aspx?playerType=1&path=" + Server.UrlEncode(root.Substring(0, root.Length - 1)) + "&mvid=" + Server.UrlEncode(PublicDownload.Serialize(root + fileParts[0])) + "\" onclick=\"EditPop5(this.href,'Add1');return false;\" >Stream</a></div>";
}
}
mediaButton += playButton + "<a href=\"" +
Download.GetDownloadUrl(false, false, Download.InternalFiles.LibraryFile,
root + fileParts[0]) +
"\">Play</a>" + endDiv;
mediaButton += downloadButton + "<a href=\"" +
Download.GetDownloadUrl(true, true, Download.InternalFiles.LibraryFile,
root + fileParts[0]) +
"\">Download</a>" + endDiv + endDiv;
library.Add(mediaButton);
}
if ((coverFilter.IsMatch(fileParts[0])))
{
ALBUM_ART.Visible = true;
ALBUM_ART.InnerHtml = albumPic1 +
Download.GetDownloadUrl(false, true, Download.InternalFiles.LibraryFile,
root + fileParts[0]) + albumPic2 + endDiv;
}
}
else
{
if (fileFilter.IsMatch(fileParts[0]))
{
library.Add(fileDiv1 + "<a href=\"?path=" + Server.UrlEncode(root.Substring(0, root.Length - 1)) + "&pic=" + Server.UrlEncode(fileParts[0]) + "\">" + fileParts[0] + "</a></div>");
}
}
}
if (photoLibrary)
{
library.Add(endDiv);
}
else
{
downloadAlbum.Visible = playAlbum.Visible;
if (playAlbum.Visible)
{
playAlbum.InnerHtml = "<a href=\"" + Download.GetDownloadUrl(false, false, Download.InternalFiles.LibraryFolder, root) + "\">Play All</a>";
downloadAlbum.InnerHtml = "<a href=\"" + Download.GetDownloadUrl(true, true, Download.InternalFiles.LibraryFolder, root) + "\">Download All</a>";
if (strmAllowed)
{
if (Mode.ToLower() == "music")
{
streamAlbum.InnerHtml = "<a href=\"public/Player2.aspx?playerType=1&?path=" + Server.UrlEncode(root.Substring(0, root.Length - 1)) + "&mid=" + Server.UrlEncode(PublicDownload.Serialize(root)) + "\"onclick=\"EditPop5(this.href,'Add1');return false;\" >Stream All</a>";
}
else
{
streamAlbum.InnerHtml = "<a href=\"public/Player2.aspx?playerType=2&?path=" + Server.UrlEncode(root.Substring(0, root.Length - 1)) + "&mid=" + Server.UrlEncode(PublicDownload.Serialize(root)) + "\"onclick=\"EditPop5(this.href,'Add1');return false;\" >Stream All</a>";
}
streamAlbum.Visible = true;
streamerSettings.Visible = true;
}
}
}
//Load all the directory/file info collected in this pass to the page for rendering
for (int a = 0; a < library.Count; a++)
{
NAV_TREE.InnerHtml += (string) library[a] + "\n";
}
}
public static string GetStreamerStatus()
{
string streamActive = "";
//Check processes running on the seerver. If VLC is running assuming streaming is active
try
{
foreach (Process thisproc in Process.GetProcessesByName("vlc"))
{
streamActive = "true";
continue;
}
}
catch (Exception Exc)
{
}
return streamActive;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
}
}